package com.xoomworks.rsfr.model;

import java.util.Date;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonFormat;

/**
 * The persistent class for the users database table.
 */
public class User extends BaseEntity {
    private static final long serialVersionUID = 1L;

    @JsonFormat(shape=JsonFormat.Shape.STRING, pattern="MMM dd, yyyy HH:mm:ss Z", timezone="CET")
    private Date createdOn;

    private String email;

    private Byte isEmailConfirmed;

    private Date lastPasswordFailure;

    @JsonFormat(shape=JsonFormat.Shape.STRING, pattern="MMM dd, yyyy HH:mm:ss Z", timezone="CET")
    private Date modifiedOn;

    private Integer passwordFailuresSinceLastLogin;

    private String passwordSalt;

    private String passwordVerificationToken;

    private Date passwordVerificationTokenExpiration;

    private String userName;

    // uni-directional many-to-one association to User
    private User modifiedBy;

    // uni-directional many-to-one association to Company
    private Company company;

    private String password;

    private Byte isDeleted = 0;

    // uni-directional many-to-many association to Role
    private List<Role> roles;

    // uni-directional many-to-one association to User
    private User createdBy;

    /**
     * Constructor with specified parameters.
     * @param createdOn Date Represents the date when the user was created.
     * @param email String Represent the user email.
     * @param passwordFailuresSinceLastLogin Integer.
     * @param userName String.
     * @param roles List<Role>.
     * @param createdBy User.
     * @param company Company.
     */
    public User(final Date createdOn, final String email, final Integer passwordFailuresSinceLastLogin,
            final String userName, final List<Role> roles, final User createdBy, final Company company) {
        super();
        this.createdOn = createdOn;
        this.email = email;
        this.passwordFailuresSinceLastLogin = passwordFailuresSinceLastLogin;
        this.userName = userName;
        this.roles = roles;
        this.createdBy = createdBy;
        this.company = company;
    }

    /**
     * Constructor with specified parameters.
     * @param email String Represent the user email.
     * @param userName String.
     * @param company Company.
     * @param roles List<Role>.
     */
    public User(final String email, final String userName, final Company company, final List<Role> roles) {
        super();
        this.email = email;
        this.userName = userName;
        this.company = company;
        this.roles = roles;
    }

    /**
     * Constructor with specified parameters.
     * @param createdOn Date.
     * @param email String.
     * @param isEmailConfirmed Byte.
     * @param lastPasswordFailure Date.
     * @param modifiedOn Date.
     * @param passwordFailuresSinceLastLogin Integer.
     * @param passwordSalt String
     * @param passwordVerificationToken String.
     * @param passwordVerificationTokenExpiration Date.
     * @param userName String.
     * @param roles List<Roles>.
     * @param createdBy User.
     * @param modifiedBy User.
     * @param company Company.
     */
    public User(final Date createdOn, final String email, final Byte isEmailConfirmed, final Date lastPasswordFailure,
            final Date modifiedOn, final Integer passwordFailuresSinceLastLogin, final String passwordSalt,
            final String passwordVerificationToken, final Date passwordVerificationTokenExpiration,
            final String userName, final List<Role> roles, final User createdBy, final User modifiedBy,
            final Company company) {
        super();
        this.email = email;
        this.createdOn = createdOn;
        this.isEmailConfirmed = isEmailConfirmed;
        this.lastPasswordFailure = lastPasswordFailure;
        this.modifiedOn = modifiedOn;
        this.passwordFailuresSinceLastLogin = passwordFailuresSinceLastLogin;
        this.passwordSalt = passwordSalt;
        this.passwordVerificationToken = passwordVerificationToken;
        this.passwordVerificationTokenExpiration = passwordVerificationTokenExpiration;
        this.userName = userName;
        this.roles = roles;
        this.createdBy = createdBy;
        this.modifiedBy = modifiedBy;
        this.company = company;
    }


    /**
     * Constructor with no fields.
     */
    public User() {
    }

    /**
     * Gets the password.
     * @return password String Represents the email.
     */
    public String getPassword() {
        return password;
    }

    /**
     * Sets the password.
     * @param password String Which is used to set the password.
     */
    public void setPassword(final String password) {
        this.password = password;
    }

    /**
     * Sets if the email is confirmed.
     * @param isEmailConfirmed Byte Which is used to set the isEmailConfirmed.
     */
    public void setEmailConfirmed(final Byte isEmailConfirmed) {
        this.isEmailConfirmed = isEmailConfirmed;
    }

    /**
     * Gets the date.
     * @return createdOn Date.
     */
    public Date getCreatedOn() {
        return this.createdOn;
    }

    /**
     * Sets the date.
     * @param createdOn Date Which is used to set the createdOn.
     */
    public void setCreatedOn(final Date createdOn) {
        this.createdOn = createdOn;
    }

    /**
     * Gets email.
     * @return email String.
     */
    public String getEmail() {
        return this.email;
    }

    /**
     * Sets the email.
     * @param email String Which is used to set the email.
     */
    public void setEmail(final String email) {
        this.email = email;
    }

    /**
     * Gets if is deleted.
     * @return isDeleted Byte.
     */
    public Byte getIsDeleted() {
        return this.isDeleted;
    }

    /**
     * Sets if is deleted.
     * @param isDeleted Byte Which is used to set the isDeleted.
     */
    public void setIsDeleted(final Byte isDeleted) {
        this.isDeleted = isDeleted;
    }

    /**
     * Gets if the email is confirmed.
     * @return isEmailConfirmed Byte.
     */
    public Byte getIsEmailConfirmed() {
        return this.isEmailConfirmed;
    }

    /**
     * Sets if the email is confirmed.
     * @param isEmailConfirmed Byte Which is used to set the isEmailConfirmed.
     */
    public void setIsEmailConfirmed(final Byte isEmailConfirmed) {
        this.isEmailConfirmed = isEmailConfirmed;
    }

    /**
     * Gets the date.
     * @return lastPasswordFailure Date.
     */
    public Date getLastPasswordFailure() {
        return this.lastPasswordFailure;
    }

    /**
     * Sets the date.
     * @param lastPasswordFailure Date Which is used to set the lastPasswordFailure.
     */
    public void setLastPasswordFailure(final Date lastPasswordFailure) {
        this.lastPasswordFailure = lastPasswordFailure;
    }

    /**
     * Gets the date.
     * @return modifiedOn Date.
     */
    public Date getModifiedOn() {
        return this.modifiedOn;
    }

    /**
     * Sets the date.
     * @param modifiedOn Date Which is used to set the modifiedOn.
     */
    public void setModifiedOn(final Date modifiedOn) {
        this.modifiedOn = modifiedOn;
    }

    /**
     * Gets the password.
     * @return passwordFailuresSinceLastLogin Integer.
     */
    public Integer getPasswordFailuresSinceLastLogin() {
        return this.passwordFailuresSinceLastLogin;
    }

    /**
     * Sets the password.
     * @param passwordFailuresSinceLastLogin Integer Which is used to set the passwordFailuresLastLogin.
     */
    public void setPasswordFailuresSinceLastLogin(final Integer passwordFailuresSinceLastLogin) {
        this.passwordFailuresSinceLastLogin = passwordFailuresSinceLastLogin;
    }

    /**
     * Gets the password.
     * @return passwordSalt String.
     */
    public String getPasswordSalt() {
        return this.passwordSalt;
    }

    /**
     * Sets the password.
     * @param passwordSalt String Which is used to set the passwordSalt.
     */
    public void setPasswordSalt(final String passwordSalt) {
        this.passwordSalt = passwordSalt;
    }

    /**
     * Gets the password.
     * @return passwordVerificationToken
     */
    public String getPasswordVerificationToken() {
        return this.passwordVerificationToken;
    }

    /**
     * Sets the password.
     * @param passwordVerificationToken String Which is used to set the passwordVerificationToken.
     */
    public void setPasswordVerificationToken(final String passwordVerificationToken) {
        this.passwordVerificationToken = passwordVerificationToken;
    }

    /**
     * Gets the password.
     * @return passwordVerificationTokenExpiration Date.
     */
    public Date getPasswordVerificationTokenExpiration() {
        return this.passwordVerificationTokenExpiration;
    }

    /**
     * Sets the password.
     * @param passwordVerificationTokenExpiration Date Which is used to set the passwordVerificationTokenExpiration.
     */
    public void setPasswordVerificationTokenExpiration(final Date passwordVerificationTokenExpiration) {
        this.passwordVerificationTokenExpiration = passwordVerificationTokenExpiration;
    }

    /**
     * Gets the user name.
     * @return userName String.
     */
    public String getUserName() {
        return this.userName;
    }

    /**
     * Sets the user name.
     * @param userName String Which is used to set the userName.
     */
    public void setUserName(final String userName) {
        this.userName = userName;
    }

    /**
     * Gets a list of roles.
     * @return roles List<Role>.
     */
    public List<Role> getRoles() {
        return this.roles;
    }

    /**
     * Sets a list of roles.
     * @param roles List<Roles> Which is used to set the roles.
     */
    public void setRoles(final List<Role> roles) {
        this.roles = roles;
    }

    /**
     * Gets an user.
     * @return createdBy User Which is used to set the createdBy.
     */
    public User getCreatedBy() {
        return this.createdBy;
    }

    /**
     * Sets a user.
     * @param createdBy User.
     */
    public void setCreatedBy(final User createdBy) {
        this.createdBy = createdBy;
    }

    /**
     * Gets a user who modified.
     * @return modifiedBy User.
     */
    public User getModifiedBy() {
        return this.modifiedBy;
    }

    /**
     * Sets a user.
     * @param modifiedBy User.
     */
    public void setModifiedBy(final User modifiedBy) {
        this.modifiedBy = modifiedBy;
    }

    /**
     * Gets a company.
     * @return company Company.
     */
    public Company getCompany() {
        return this.company;
    }

    /**
     * Sets the company.
     * @param company Company.
     */
    public void setCompany(final Company company) {
        this.company = company;
    }

    /*
     * (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        return "User [createdOn=" + createdOn + ", email=" + email + ", isEmailConfirmed=" + isEmailConfirmed
                + ", lastPasswordFailure=" + lastPasswordFailure + ", modifiedOn=" + modifiedOn
                + ", passwordFailuresSinceLastLogin=" + passwordFailuresSinceLastLogin + ", passwordSalt="
                + passwordSalt + ", passwordVerificationToken=" + passwordVerificationToken
                + ", passwordVerificationTokenExpiration=" + passwordVerificationTokenExpiration + ", userName="
                + userName + ", roles=" + roles + ", createdBy=" + createdBy + ", modifiedBy=" + modifiedBy
                + ", company=" + company + ", password=" + password + ", isDeleted=" + isDeleted + "]";
    }

    /*
     * (non-Javadoc)
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = (prime * result) + ((email == null) ? 0 : email.hashCode());
        result = (prime * result) + ((isDeleted == null) ? 0 : isDeleted.hashCode());
        result = (prime * result) + ((isEmailConfirmed == null) ? 0 : isEmailConfirmed.hashCode());
        result = (prime * result) + ((roles == null) ? 0 : roles.hashCode());
        result = (prime * result) + ((userName == null) ? 0 : userName.hashCode());
        return result;
    }

    /*
     * (non-Javadoc)
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(final Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final User other = (User) obj;
        if (email == null) {
            if (other.email != null) {
                return false;
            }
        } else if (!email.equals(other.email)) {
            return false;
        }
        if (isDeleted == null) {
            if (other.isDeleted != null) {
                return false;
            }
        } else if (!isDeleted.equals(other.isDeleted)) {
            return false;
        }
        if (isEmailConfirmed == null) {
            if (other.isEmailConfirmed != null) {
                return false;
            }
        } else if (!isEmailConfirmed.equals(other.isEmailConfirmed)) {
            return false;
        }
        if (roles == null) {
            if (other.roles != null) {
                return false;
            }
        } else if (!roles.equals(other.roles)) {
            return false;
        }
        if (userName == null) {
            if (other.userName != null) {
                return false;
            }
        } else if (!userName.equals(other.userName)) {
            return false;
        }
        return true;
    }

}
